let ref = ['[object Map]', '[object Set]', '[object WeakMap]', '[object WeakSet]', '[object Date]', '[object RegExp]', '[object Error]']
const deepClone = function (obj) {
    let res = {}
    let type = Object.prototype.toString.call(obj)
    if (type === '[object Object]') {
        for (let key in obj) {
            if (Object.hasOwnProperty.call(obj,key)) {
                res[key] = deepClone(obj[key])
            }
        }
    } else if (type === '[object Array]') {
        res = []
        obj.forEach((element, index) => {
            res[index] = deepClone(element)
        });
    } else if (ref.includes(type)) {
        res = new obj.constructor(obj)
    } else {
        res = obj
    }
    return res
}


//用例
const map = new Map();
map.set("key", "value");
map.set("ConardLi", "coder");

const set = new Set();
set.add("ConardLi");
set.add("coder");

const target = {
    field1: 1,
    field2: undefined,
    field3: {
        child: "child",
    },
    field4: [2, 4, 8],
    empty: null,
    map,
    set,
    bool: new Boolean(true),
    num: new Number(2),
    str: new String(2),
    symbol: Object(Symbol(1)),
    date: new Date(),
    reg: /\d+/,
    func1: () => {
        let t = 0;
        console.log("coder", t++);
    },
    func2: function (a, b) {
        return a + b;
    },
};
target.target=target
//测试代码
const test1 = deepClone(target);
console.log(target);
target.field4.push(9);
console.log('test1: ', test1);